package cn.outsourcing.supermarket.service.impl;

import cn.outsourcing.supermarket.common.constants.CommonConstants;
import cn.outsourcing.supermarket.common.exception.SupermarketException;
import cn.outsourcing.supermarket.dto.backstage.BackstageShowSettingsDTO;
import cn.outsourcing.supermarket.mapper.HiolabsShowSettingsMapper;
import cn.outsourcing.supermarket.po.HiolabsShowSettings;
import cn.outsourcing.supermarket.service.HiolabsShowSettingsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 服务实现类
 *
 * @author gzkemays
 * @since 2021-10-21
 */
@Service
public class HiolabsShowSettingsServiceImpl
    extends ServiceImpl<HiolabsShowSettingsMapper, HiolabsShowSettings>
    implements HiolabsShowSettingsService {
  @Resource private HiolabsShowSettingsMapper showSettingsMapper;

  @Override
  public HiolabsShowSettings showSettings() {
    return showSettingsMapper.selectById(1L);
  }

  @Override
  public HiolabsShowSettings showSetStore(BackstageShowSettingsDTO dto) {
    HiolabsShowSettings hiolabsShowSettings = new HiolabsShowSettings();
    hiolabsShowSettings.setId(dto.getId());
    hiolabsShowSettings.setBanner(dto.getBanner());
    hiolabsShowSettings.setChannel(dto.getChannel());
    hiolabsShowSettings.setNotice(dto.getNotice());
    hiolabsShowSettings.setIndexBannerImg(dto.getIndexBannerImg());
    if (showSettingsMapper.updateById(hiolabsShowSettings) > 0) {
      return hiolabsShowSettings;
    }
    throw new SupermarketException(CommonConstants.SQL_FAIL_CODE, "更新失败");
  }
}
